package com.th.apicenter.rta;

import com.google.protobuf.InvalidProtocolBufferException;
import com.th.apicenter.rta.proto.BaiduRtaApiRequestProtobuf;
import com.th.apicenter.rta.service.BaiduRTAService;
import com.th.apicenter.tools.ThResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author kay
 * @date 2025/6/6
 * @TODO
 */
@RestController
@RequestMapping("/baidurta")
@Slf4j
public class BaiduRTAController {

    @Autowired
    private BaiduRTAService baiduRTAService;

    /**
     * 接收百度的rta请求
     *
     * @return
     */
    @PostMapping(value = "/receive", consumes = "application/x-protobuf")
    public ThResult handleBaiduRta(@RequestBody byte[] data) {
        try {
            BaiduRtaApiRequestProtobuf.RtaApiRequest rtaApiRequest = BaiduRtaApiRequestProtobuf.RtaApiRequest.parseFrom(data);
            baiduRTAService.receiveRTA(rtaApiRequest);
        } catch (InvalidProtocolBufferException e) {
            e.printStackTrace();
        }
        return ThResult.success("true");
    }


}
